<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>应急信息发布项目审核查看</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link href="../../layui/css/iconfont/iconfont.css" rel="stylesheet" type="text/css">
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <script src="../../layui/layui.js"></script>
    <script src="../../js/jquery-1.8.3.js"></script>
    <script src="../../js/util.js"></script>
    <script>
        layui.use(['form', 'jquery', 'element', 'laydate', 'layer'], function () {
            var form = layui.form;
            var $ = layui.$;
            var laydate = layui.laydate;
            var layer = layui.layer;
            var checkId = getUrlParam("checkId");
            var mgrId = getUrlParam("mgrId");
            var userDuty = getUrlParam("userDuty")
            var checkDetail;
            var mgrTemplate;
            laydate.render({
                elem: '#startTime'
            });
            laydate.render({
                elem: '#endTime'
            });
            $('#yes').on('click', function () {
                var param = {
                    checkId:checkId
                };
                var url = '/xuYiContentCheck/dealCheckResult';
                $.ajax({
                    type: 'post',
                    async: false,
                    url: url,
                    data: param,
                    beforeSend: function () {
                        if ($("#remark").val() == "") {
                            layer.msg("审核说明不能为空");
                            return false;
                        }
                        loading = layer.load(0, {shade: false});
                    },
                    success: function (json) {
                        layer.close(loading);
                        var data = json.data;
                        if (json.retCode == 0) {
                            changeMgrCheckState();
                            updateCheckState('1');
                            layui.use('layer', function () {
                                layer.open({
                                    content:'审核成功，点击确定按钮返回审核管理界面'
                                    ,closeBtn:0
                                    , btn: ['确定']
                                    , yes: function (index) {
                                        findMgrTemplate();
                                        layer.close(index);
                                        var mgrIdState="";;

                                        if(mgrTemplate.mgrState==0){
                                            mgrIdState=" 开启 ";
                                        }else if(mgrTemplate.mgrState==1){
                                            mgrIdState=" 暂停 ";
                                        }else if(mgrTemplate.mgrState==2){
                                            mgrIdState=" 关闭 ";
                                        }else if(mgrTemplate.mgrState==3){
                                            mgrIdState=" 配置中 ";
                                        }
                                        //修改项目状态 count
                                        /*if(json.count!=0){

                                        }*/
                                        layer.confirm('目前该项目状态为'+mgrIdState+'，是否需要开启项目？', {btn: ['开启', '取消'],icon: 3, title: '提示'}, function (index) {
                                            var turl = "/mgrTemplate/modifyMgrState";
                                            var tparam = {
                                                id: mgrId,
                                                mgrState: 0,
                                                templateState:2
                                            };
                                            $.ajax({
                                                type: 'post',
                                                data: tparam,
                                                url: turl,
                                                beforeSend: function () {
                                                },
                                                success: function (tjson) {
                                                    if (tjson.code == 0) {
                                                        //变更同步
                                                        var turl = "/SmsChange/findChangeByMgrId";
                                                        var tparam = {
                                                            mgrId : mgrId
                                                        };
                                                        $.ajax({
                                                            type : 'post',
                                                            data : tparam,
                                                            url : turl,
                                                            success : function(tjson) {
                                                                console.info(tjson);
                                                            }
                                                        })
                                                        layer.confirm('修改成功', {
                                                            btn: ['确定'] //按钮
                                                        }, function () {

                                                            location.href = "xuYiContentCheck.html";

                                                        });
                                                    }else {
                                                        layer.msg(tjson.data.msg);
                                                    }
                                                },
                                                complete: function () {
                                                }
                                            });
                                        },  function (index) {
                                            location.href = "xuYiContentCheck.html";
                                        });
                                    }
                                });
                            });
                        } else {
                            layer.msg(json.msg);
                        }
                    }
                    ,
                    error: function (data) {
                        layer.msg('系统异常，请联系管理员处理!');
                    }
                });
            });

            $('#no').on('click', function () {
                var param = {
                    checkId:checkId
                };
                var url = '/xuYiContentCheck/dealCheckResult';
                $.ajax({
                    type: 'post',
                    async: false,
                    url: url,
                    data: param,
                    beforeSend: function () {
                        if ($("#remark").val() == "") {
                            layer.msg("审核说明不能为空");
                            return false;
                        }
                        loading = layer.load(0, {shade: false});
                    },
                    success: function (json) {
                        layer.close(loading);
                        updateCheckState('2');
                        var data = json.data;
                        if (json.retCode == 0) {
                            //变更同步
                            var turl = "/SmsChange/findChangeByMgrId";
                            var tparam = {
                                mgrId : mgrId
                            };
                            $.ajax({
                                type : 'post',
                                data : tparam,
                                url : turl,
                                success : function(json) {
                                    console.info(json);
                                }
                            })
                            layui.use('layer', function () {
                                layer.msg('审核成功，点击确定按钮返回审核管理界面', {
                                    time: 0 //不自动关闭
                                    , btn: ['确定']
                                    , yes: function (index) {
                                    	var turl = "/busi/modify";
				                            var tparam = {
				                                id: mgrId,
				                                state: 2
				                            };
				                            $.ajax({
				                                type: 'post',
				                                data: tparam,
				                                url: turl,
				                                beforeSend: function () {
				                                },
				                                success: function (tjson) {
				                                    if (tjson.code == 0) {
				                                       location.href = "xuYiContentCheck.html";
				                                    }
				                                    else {
				                                       layer.msg(tjson.data.msg);
				                                    }
				                                },
				                                complete: function () {
				                                }
				                            });
                                        layer.close(index);
                                        location.href = "xuYiContentCheck.html";
    								}
                                });
                            });
                        } else {
                            layer.msg(json.msg);
    					}
    				},
                    error: function (data) {
                        layer.msg('系统异常，请联系管理员处理!');
                    }
                });
            });

            function findMgrTemplate(){
                var url = '/mgrTemplate/findMgrTemplateByMgrId';
                var param = {
                    mgrId: mgrId
                };
                $.ajax({
                    type: 'post',
                    async: false,
                    url: url,
                    data: param,
                    beforeSend: function () {
                        loading = layer.load(0, {shade: false});
                    },
                    success: function (json) {
                        mgrTemplate = json.data;

                    },
                    error: function (data) {
                        layer.msg('系统异常，请联系管理员处理!');
                    }
                });
            }
            //变更项目审核状态
            function changeMgrCheckState(){
                var turl = "/mgrTemplate/modifyMgrState";
                var tparam = {
                    id: mgrId,
                    templateState:2
                };
                $.ajax({
                    type: 'post',
                    data: tparam,
                    url: turl,
                    beforeSend: function () {
                    },
                    success: function () {
                    },
                    complete: function () {
                    }
                });
            }

            //变更短信内容审核表中的审核状态
            function updateCheckState(checkState){
                var url = '/xuYiContentCheck/updateCheckInfo'
                var param = {
                    checkState : checkState,
                    remark : $("#remark").val(),
                    checkId : checkId
                }
                $.ajax({
                    contentType:"application/json;charset=UTF-8",
                    type: 'post',
                    async: false,
                    url: url,
                    data: JSON.stringify(param),
                    dataType:'json',
                    success: function (json) {
                        layer.close(loading);
                        console.info("审核表状态已改变")
                    },
                    error: function (data) {
                        layer.msg('系统异常，请联系管理员处理!');
                    }
                });
            }

            function jugdeDuty(){

                if(userDuty=="1"||userDuty=="0"){
                    $('#yes')[0].style.display = 'inline-block';
                    $('#no')[0].style.display = 'inline-block';
                }

                if(userDuty == "7"||checkDetail.checkState =="1"||checkDetail.checkState =="2"){
                    $('#yes').hide();
                    $('#no').hide();
                    $("#back")[0].style.display = "inline-block";
                }
                if(userDuty == "7"&&checkDetail.checkState =="0"){
                    //$('#checkRemark').hide();
                    $('#remark').attr("disabled",true);
                    $("#back")[0].style.display = "inline-block";
                }
            }

            function findCheckDetail(){
                var url = '/xuYiContentCheck/findCheckDetail';
                var param = {
                    checkId: checkId
                };
                $.ajax({
                    contentType:"application/json;charset=UTF-8",
                    type: 'post',
                    async: false,
                    url: url,
                    data: JSON.stringify(param),
                    dataType:'json',
                    beforeSend: function () {
                        loading = layer.load(0, {shade: false});
                    },
                    success: function (json) {
                        layer.close(loading);
                        checkDetail = json.data;
                        //$("#startTime").val(data.startDate);
                        //$("#endTime").val(data.endDate);
                        $('#mgrName').val(checkDetail.mgrName);
                        $('#content').val(checkDetail.mgrContent);
                        if("0"==checkDetail.checkState){
                            $('#checkState').val("待审核");
                            $("#back")[0].style.display = "none";
                        }else if("1"==checkDetail.checkState){
                            $('#checkState').val("审核通过");
                            $('#remark').val(checkDetail.remark);
                            $('#remark').attr("disabled",true);
                            $("#back")[0].style.display = "inline-block";
                        }else if("2"==checkDetail.checkState){
                            $('#checkState').val("审核不通过");
                            $('#remark').val(checkDetail.remark);
                            $('#remark').attr("disabled",true);
                            $("#back")[0].style.display = "inline-block";
                        }



                        //console.info(JSON.stringify(data));
                        //$('#countyName').val(data.countyName);
                        //$('#mgrName').val(data.mgrName);
                    }
                    ,
                    error: function (data) {
                        layer.msg('系统异常，请联系管理员处理!');
                    }
                });
            }
            //页面数据初始化
            $(document).ready(function () {
                findCheckDetail();
                jugdeDuty();
            });

            $('#back').on('click', function (){
                location.href = "xuYiContentCheck.html";
            });
        });
    </script>
</head>
<body>
<div class="layui-html-limit">
    <div class="layui-content-body">
        <div class="scroll-box">
            <div class="breadcrumb-box">
              <span class="layui-breadcrumb" lay-separator="|">
     <a href="javascript:returnIndex2()">首页&nbsp;</a>
     <a href="#"> &nbsp;项目短信内容审核&nbsp; </a>
</span>
         </div>
         <div class="content-box">
         <div class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                        <div class="layui-block" pane="">
                            <label class="layui-form-label">项目名称</label>
                            <div class="layui-input-block">
                                <input type="text" style="width:auto"
                                       id="mgrName" autocomplete="off" class="layui-input" disabled>
                            </div>
                        </div>
                    </div>
							<div class="layui-form-item">
								<div class="layui-block" pane="">
									<label class="layui-form-label">短信内容</label>
									<div class="layui-input-block">
										<textarea placeholder="请输入内容" class="layui-textarea"
											style="width: 30%" id="content" disabled></textarea>
									</div>
								</div>
							</div>
                    <div class="layui-form-item">
                        <div class="layui-block" pane="">
                            <label class="layui-form-label">审核状态</label>
                            <div class="layui-input-block">
                                <input type="text" style="width:auto"
                                id="checkState" autocomplete="off" class="layui-input" disabled>
                             </div>
                        </div>
                     </div>
							<!--  <div class="layui-form-item">
                        <div class="layui-block">
                            <label class="layui-form-label" style="width: auto">发送起止时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="date" id="startTime" autocomplete="off" class="layui-input"
                                       disabled>
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline">
                                <input type="text" name="date" id="endTime" autocomplete="off" class="layui-input"
                                       disabled>
                            </div>
                        </div>
                    </div> -->
							<div class="layui-form-item" id = "checkRemark">
								<label class="layui-form-label">审核说明</label>
								<div class="layui-input-block">
									<textarea placeholder="请输入内容" class="layui-textarea"
										style="width: 30%" id="remark"></textarea>
								</div>
							</div>
							<div class="layui-form-item">
								<button class="layui-btn layui-btn-normal" id="yes" style = 'display: none;'>审核通过</button>
								<button class="layui-btn layui-btn-danger" id="no" style = 'display: none;'>审核不通过</button>
                                <button class="layui-btn layui-btn-normal" id="back" style="display:none">返回</button>
							</div>
						</div>

					</div>
        </div>
    </div>
</div>
</div>

</body>
</html>